package dev.ece.util.lib;

import java.nio.ByteBuffer;
import java.nio.IntBuffer;

public class Vector2i {

	private int[] vector;
	
	public Vector2i() {
		this(0, 0);
	}
	
	public Vector2i(int x, int y) {
		this(new int[] {x, y});
	}
	
	protected Vector2i(int[] vector) {
		this.vector = vector;
	}
	
	public int[] getVector() {
		return vector;
	}
	
	public int getX() {
		return vector[0];
	}
	
	public int getY() {
		return vector[1];
	}
	
	public void store(IntBuffer buff) {
		buff.put(this.getVector());
	}
	
	public void store(ByteBuffer buff) {
		for (int i = 0; i < this.getVector().length; i++) {
			buff.putInt(this.getVector()[i]);
		}
	}
	
	public void add(Vector2i vector) {
		for(int i=0; i<this.vector.length; i++) {
			this.vector[i] +=  vector.vector[i];
		}
	}
	
	public void mul(int num) {
		for(int i=0; i<vector.length; i++) {
			vector[i] *= num; 
		}
	}
	
	public String toString() {
		StringBuilder s = new StringBuilder();
		s.append("(");
		int len = this.vector.length - 1;
		for(int i=0; i<this.vector.length; i++) {
			s.append(this.vector[i]);
			if(i < len) {
				s.append(",");
			}
		}
		s.append(")");
		return s.toString();
	}
}
